/*
 * Copyright 2017 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "board.h"
#include "fsl_gpio.h"
#include "clock_config.h"
#include "pin_mux.h"
#include "systask.h"
#include "ledctr.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
void BOARD_BootClockPLL100M(void);
void modbus_task (void const *argument);

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*!
 * @brief Main function
 */
int main(void)
{
    /* Define the init structure for the output LED pin*/
    gpio_pin_config_t led_config = {
        kGPIO_DigitalOutput,
        0,
    };

    BOARD_BootClockPLL100M();
    
    /* Board pin init */
    BOARD_InitPins();

    /* Init output LED GPIO. */
    GPIO_PortInit(GPIO, BOARD_LED_BLUE_GPIO_PORT);
    GPIO_PinInit(GPIO, BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, &led_config);
    GPIO_PinInit(GPIO, BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, &led_config);
    GPIO_PinInit(GPIO, BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, &led_config);

    /* Set systick reload value to generate 1ms interrupt */
    if (SysTick_Config(SystemCoreClock / 1000U))
    {
        while (1){}
    }

    while (1)
    {
        LedTask();
        SysTask();
        modbus_task("en");
    }
}

/*!
 * @brief system init hook , startup 
 */
void SystemInitHook(void)
{
    
}
